import { Entity, Column, ManyToOne, JoinColumn } from "typeorm";

import type { VARCHAR50_PG, Access, User, VARCHAR255_PG, SMALLINT_PG } from "qqlx-core";
import { AccessGateway } from "qqlx-core";

import { TransformerSmallInt } from "@lib/orm.transfor.number";
import { TransformerVarchar50, TransformerVarchar255 } from "@lib/orm.transfor.string";

import { OwnerIdSchema } from "@/alpha/ext.id.base";

@Entity({ name: AccessGateway.relations })
export class AccessSchema extends OwnerIdSchema implements Access {
  @Column({ transformer: new TransformerVarchar255() })
  scope: VARCHAR255_PG = "";

  @Column({ transformer: new TransformerSmallInt() })
  droit: SMALLINT_PG = 0;

  @Column({ transformer: new TransformerVarchar50() })
  refVisitorId!: VARCHAR50_PG;

  @ManyToOne("UserSchema")
  @JoinColumn({ name: "refVisitorId", referencedColumnName: "uuid32" })
  justVisitor!: User;
}
